package com.api.gbhg.huangwm.web;

import com.api.gbhg.huangwm.dao.YuSuanTiaoZhengDao;
import com.engine.common.util.ParamUtil;
import org.opensaml.xml.signature.Y;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Huangwm
 * @Date 2022-06-22
 * @Version 1.0
 * @Description TODO
 **/
@Path("/gb/huangwm/ystz")
public class YuSuanTiaoZhengApi {

    private YuSuanTiaoZhengDao dao = new YuSuanTiaoZhengDao();

    @GET
    @Path("/hasMobileFunds")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> hasMobileFunds(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiResult = new HashMap<>();
        try{
            Map<String, Object> requestParam = ParamUtil.request2Map(request);
            User user = HrmUserVarify.getUser(request,response);
            apiResult = dao.hasMobileFunds(user);
        }catch (Exception e){
            e.printStackTrace();
            apiResult.put("apiStatus",false);
            apiResult.put("hasRight",false);
            apiResult.put("msg",e.getMessage());
        }
        return apiResult;
    }

    @GET
    @Path("/getProjectInfo")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getProjectInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apiResult = new HashMap<>();
        try{
            Map<String, Object> requestParam = ParamUtil.request2Map(request);
            String xmid = requestParam.getOrDefault("xmid","0").toString();
            User user = HrmUserVarify.getUser(request,response);
            apiResult = dao.getProjectInfo(xmid);
        }catch (Exception e){
            e.printStackTrace();
            apiResult.put("apiStatus",false);
            apiResult.put("msg",e.getMessage());
        }
        return apiResult;
    }
}
